package com.bdk.middle.goods.web;


import com.bdk.middle.common.domain.PageDO;
import com.bdk.middle.common.result.ResultDO;
import com.bdk.middle.common.result.web.ObjectResponse;
import com.bdk.middle.goods.api.domain.GoodsViewsRecordDO;
import com.bdk.middle.goods.api.query.GoodsViewsRecordQueryDO;
import com.bdk.middle.goods.service.GoodsViewsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  商品浏览记录
 * </p>
 *
 * @author Reagan
 * @since 2021-03-18
 */

@Api(tags = "商品浏览记录管理相关接口")
@RestController
@RequestMapping("/goods-views-record")
public class GoodsViewsRecordController {

    @Autowired
    private GoodsViewsRecordService goodsViewsRecordService;
    @ApiOperation(value="商品浏览记录新增", notes="商品浏览记录新增")
    @RequestMapping(value="/add.html", method = RequestMethod.POST)
    public @ResponseBody
    ObjectResponse add(@RequestBody GoodsViewsRecordDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = goodsViewsRecordService.add(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

    @ApiOperation(value="商品浏览记录列表", notes="商品浏览记录列表")
    @RequestMapping(value="/list.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse list(@RequestBody GoodsViewsRecordQueryDO domain) {

        ObjectResponse<PageDO<GoodsViewsRecordDO>> response = new ObjectResponse();

        ResultDO result = goodsViewsRecordService.find(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((PageDO<GoodsViewsRecordDO>) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }
}

